<template>
  <view class="tab-bar">
    <view
      class="tab-bar-item"
      v-for="item in tabBar"
      :key="item.id"
      :class="{ 'active' : currentIndex === item.id }"
      @click="tabBarClick(item.id)"
    >{{ item.name }}</view>
  </view>
</template>

<script>
  export default {
    data () {
      return {
        tabBar: [
          {
            id: 0,
            name: '综合'
          },
          {
            id: 1,
            name: '销量'
          },
          {
            id: 2,
            name: '价格'
          }
        ],
        currentIndex: 0
      }
    },
    methods: {
      tabBarClick (index) {
        this.currentIndex = index
        this.$emit('itemClick', index)
      }
    }
  }
</script>

<style lang="less" scoped>
  .tab-bar {
    display: flex;
    .tab-bar-item {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      border-bottom: 5rpx solid #eee;
      padding: 15rpx 0;
    }
    .active {
      color: #eb4450;
      border-color: #eb4450;
    }
  }
</style>
